#include "widget.h"
#include "./ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 初始化下拉框
    ui->comboBox->addItem("巨无霸");
    ui->comboBox->addItem("麦辣鸡腿堡");
    ui->comboBox_2->addItem("薯条");
    ui->comboBox_2->addItem("麦辣鸡翅");
    ui->comboBox_3->addItem("可乐");
    ui->comboBox_3->addItem("雪碧");
    // 初始化微调框
    ui->spinBox->setValue(1);
    ui->spinBox->setRange(1, 5);
    ui->spinBox_2->setValue(1);
    ui->spinBox_2->setRange(1, 5);
    ui->spinBox_3->setValue(1);
    ui->spinBox_3->setRange(1, 5);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    qDebug() << "点餐成功！"
             <<ui->comboBox->currentText()<<":"
             <<ui->spinBox->value()<< "份"
             <<ui->comboBox_2->currentText()<<":"
             <<ui->spinBox_2->value()<< "份"
             <<ui->comboBox_3->currentText()<<":"
             <<ui->spinBox_3->value()<< "份";
    // 计算总价
    double totalPrice = 0;
    if (ui->comboBox->currentText() == "巨无霸") {
        totalPrice += 20 * ui->spinBox->value();
    } else if (ui->comboBox->currentText() == "麦辣鸡腿堡") {
        totalPrice += 15 * ui->spinBox->value();
    }
    if (ui->comboBox_2->currentText() == "薯条") {
        totalPrice += 10 * ui->spinBox_2->value();
    } else if (ui->comboBox_2->currentText() == "麦辣鸡翅") {
        totalPrice += 12 * ui->spinBox_2->value();
    }
    if (ui->comboBox_3->currentText() == "可乐") {
        totalPrice += 5 * ui->spinBox_3->value();
    } else if (ui->comboBox_3->currentText() == "雪碧") {
        totalPrice += 6 * ui->spinBox_3->value();
    }
    qDebug() << "总价：" << totalPrice << "元";
}

